package com.tledu.production.controller.system;

import com.tledu.production.core.result.AjaxResult;
import com.tledu.production.service.system.ISysRoleResService;
import lombok.AllArgsConstructor;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttributes;

/**
 * @author Antg
 * @date 2021/8/19  12:32
 */
@RestController
@AllArgsConstructor
@RequestMapping("/system/roleRes")
@SessionAttributes(value = {"roleId"})
public class SysRoleResController {
    private final ISysRoleResService sysRoleResService;

    @GetMapping("/findRoleRes")
    public AjaxResult<Integer[]> findRoleRes(Model model) {
        String roleId = (String) model.getAttribute("roleId");
        Integer[] roleRes = sysRoleResService.findRoleRes(roleId);
        return new AjaxResult<>(roleRes);
    }

    @GetMapping("/updateRoleRes")
    public AjaxResult updateRoleRes(String resList, Model model) {
        String roleId = (String) model.getAttribute("roleId");
        int result = sysRoleResService.updateRoleRes(roleId, resList);
        if (result >= 1) {
            return new AjaxResult("更新成功");
        } else {
            return new AjaxResult("跟新失败", 500);
        }
    }
}
